﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Globalization;
using System.Threading;
using System.Reflection;
namespace Helper
{
    public static class LangHelpers
    {
        static System.Resources.ResourceManager rm;
        //CultureInfo ci;
        static string _cultureInfoName = "en";

        public static string GetLang
        {
            get { return _cultureInfoName; }
        }

        public static void init(string cultureInfoName)
        {
            try
            {
                _cultureInfoName = cultureInfoName;
                //Create culture info object 
                CultureInfo ci = new CultureInfo(_cultureInfoName);

                System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
                System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
               // rm = new System.Resources.ResourceManager("LanguageResource", System.Reflection.Assembly.GetExecutingAssembly());
               // rm = new System.Resources.ResourceManager("Resources.LanguageResource", System.Reflection.Assembly.Load("App_GlobalResources"));
            }
            catch (Exception ex)
            {
                throw new Exception("LangHelpers::init=>" + ex.Message);
            }

        }
        public static string GetString(string Key)
        {
            string _result = "";
            try
            {
                _result = System.Web.HttpContext.GetGlobalResourceObject("Resource", Key) + "";
                //_result = rm.GetString(Key, Thread.CurrentThread.CurrentCulture);
            }
            catch (Exception ex)
            {
                _result = "?????";
                //throw new Exception(ex.Message);
            }
            return _result;
        }
    }
}